package com.rjyb.student_management_platform.dao;

import com.rjyb.student_management_platform.pojo.AnswerSheet;
import com.rjyb.student_management_platform.pojo.Booksubject;
import com.rjyb.student_management_platform.pojo.Class;
import com.rjyb.student_management_platform.pojo.Jobtable;
import com.rjyb.student_management_platform.unit.common.Pager;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface AnswerDao {
    //1.查询个人老师班级
    @Select("select c2.* from `class_teacher` c ,class c2 where c.cid=c2.cid and c.tid=#{id}")
    List<Class> classid(long id);

    //2.查询课目
    @Select("select b.* from booksubject b,teacher t where tid=#{id} and t.bid=b.bid")
    Booksubject selBooksubject(long id);

    //3.上传作业
    @Insert("insert into jobtable values(null,#{jobName},#{jobSrc},#{jobSrc1},#{jobSrc2},#{jobSrc3},#{tid},#{bid},#{cid},#{jobData})")
    void addJobtable(Jobtable jobtable);
    //4.查答题表
    @Select("SELECT * FROM answer_sheet a ,student s,class c ,jobtable j WHERE a.jid=#{jid} AND a.jid=j.jid AND s.sid=a.sid AND j.cid=c.cid ORDER BY a.answerTime DESC  limit #{pager.beginIndex},#{pager.pageSize}")
    List<Map> selectall(@Param("pager") Pager pager, @Param("jid") Integer jid);
    //5.查作业表并排序
    @Select("SELECT * FROM jobTable where tid=${tid}  ORDER BY jobData DESC  ")
    List<HashMap> selectSumHomeWork(Integer teacherId);
    //6.分页查询
    @Select("select count(*) from  answer_sheet a where a.jid=#{jid} ")
    int selstucount(@Param("jid") Integer jid );

    //7.有更改
    @Update("update answer_sheet  SET correct=#{correct},remedy=#{remedy},mistake=#{mistake} where jid=#{jid} and sid=#{sid}")
    boolean updateWork(@Param("correct") Integer correct,@Param("remedy") Integer remedy,@Param("jid") Integer jid,@Param("sid") Integer sid,@Param("mistake")String mistake);
    //8.查答题表的数据
    @Select("select * from  answer_sheet a , student s where a.jid=#{jid} and a.sid=#{sid} and s.sid=a.sid")
    List<HashMap> selectimg(Integer jid,Integer sid);
    //9.
    @Select("SELECT * FROM  class_student cs,jobTable jt,student s,bookSubject bs,class c WHERE cs.sid=${sid} AND cs.cid=jt.cid AND s.sid=cs.sid AND bs.bid=jt.bid AND c.cid=jt.cid ORDER BY jt.jobData DESC")
    List<HashMap> selectHomeWork(Long sid);
    //10.通过答案判断做没做
    @Select("SELECT answer FROM answer_sheet a WHERE a.jid=${jid} AND a.sid=${sid};")
    String ifHomeWork1(Integer jid,Integer sid);
    //11.查询某个学生所有的作业
    @Select("SELECT * FROM answer_sheet a ,jobtable jt, student s,bookSubject bs WHERE a.jid=${jid} AND a.sid=${sid} and s.sid=a.sid and jt.jid=a.jid and jt.bid=bs.bid;")
    HashMap ifHomeWork(Integer jid,Integer sid);
    //12.添加作业答案
    @Insert("insert into answer_sheet values(null,#{jid},#{answer},#{imgsrc},#{imgsrc1},#{imgsrc2},#{imgsrc3},1,1,null,#{sid},#{answerTime})")
    void addAnswerSheet(AnswerSheet answerSheet);
    //13.查老师发布的作业
    @Select("select * from jobTable jt,teacher t,bookSubject bs where jt.jid=${jid} And jt.tid=t.tid and jt.bid=bs.bid")
    List<HashMap> selectTeacherName(Integer jid);
    //14.拿没过的作业
    @Select("<script>\n"+
            "select a.*,b.subjectName,t.name,j.jobName from answer_sheet a,jobtable j,booksubject b,teacher t where a.sid=#{sid} and a.remedy=2 and a.jid=j.jid and j.bid=b.bid and t.tid=j.tid\n"+
            "<if test='aid!=null and aid!=\"\"'>and a.aid=#{aid}</if>"+
            "</script>")
    List<Map> TakeHomework(long sid, String aid);

    //15.提交修改后的作业
    @Update("update answer_sheet set answer=#{answer},imgsrc=#{imgsrc},imgsrc1=#{imgsrc1},imgsrc2=#{imgsrc2},imgsrc3=#{imgsrc3},correct=1,remedy=1,answerTime=#{answerTime} where aid=#{aid}")
    void UpdateAnswerSheet(AnswerSheet answerSheet);

}